<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>智慧农业——大数据后台展示设计 | XiaoZiYan</title><meta name="keywords" content="智慧农业,PCB,大数据"><meta name="author" content="XiaoZiYan"><meta name="copyright" content="XiaoZiYan"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="智慧农业PCB大数据">
<meta property="og:type" content="article">
<meta property="og:title" content="智慧农业——大数据后台展示设计">
<meta property="og:url" content="https://xiaoziyanxiaoludan.gitee.io/xiaoziyan/2021/08/06/%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A%E5%A4%A7%E6%95%B0%E6%8D%AE%E8%AE%BE%E8%AE%A1/index.html">
<meta property="og:site_name" content="XiaoZiYan">
<meta property="og:description" content="智慧农业PCB大数据">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://xiaoziyan.top/images/3205a9c3fa4e72ebd71a6101d2812929.jpeg">
<meta property="article:published_time" content="2021-08-06T10:12:02.000Z">
<meta property="article:modified_time" content="2022-11-03T10:28:35.214Z">
<meta property="article:author" content="XiaoZiYan">
<meta property="article:tag" content="智慧农业">
<meta property="article:tag" content="PCB">
<meta property="article:tag" content="大数据">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://xiaoziyan.top/images/3205a9c3fa4e72ebd71a6101d2812929.jpeg"><link rel="shortcut icon" href="/xiaoziyan/img/favicon.png"><link rel="canonical" href="https://xiaoziyanxiaoludan.gitee.io/xiaoziyan/2021/08/06/%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A%E5%A4%A7%E6%95%B0%E6%8D%AE%E8%AE%BE%E8%AE%A1/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta/><link rel="stylesheet" href="/xiaoziyan/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/xiaoziyan/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: XiaoZiYan","link":"链接: ","source":"来源: XiaoZiYan","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '智慧农业——大数据后台展示设计',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-11-03 18:28:35'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="./css/custom.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.css"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/xiaoziyan/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/xiaoziyan/archives/"><div class="headline">文章</div><div class="length-num">33</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/xiaoziyan/tags/"><div class="headline">标签</div><div class="length-num">41</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/xiaoziyan/categories/"><div class="headline">分类</div><div class="length-num">39</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/xiaoziyan/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 多媒体</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/xiaoziyan/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/xiaoziyan/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('http://xiaoziyan.top/images/3205a9c3fa4e72ebd71a6101d2812929.jpeg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/xiaoziyan/">XiaoZiYan</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/xiaoziyan/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 多媒体</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/xiaoziyan/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/xiaoziyan/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">智慧农业——大数据后台展示设计</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-08-06T10:12:02.000Z" title="发表于 2021-08-06 18:12:02">2021-08-06</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-11-03T10:28:35.214Z" title="更新于 2022-11-03 18:28:35">2022-11-03</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/xiaoziyan/categories/%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A/">智慧农业</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/xiaoziyan/categories/%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A/PCB/">PCB</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/xiaoziyan/categories/%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A/PCB/%E5%A4%A7%E6%95%B0%E6%8D%AE/">大数据</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="智慧农业——大数据后台展示设计"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="大数据相关知识"><a href="#大数据相关知识" class="headerlink" title="大数据相关知识"></a>大数据相关知识</h1><h2 id="大数据"><a href="#大数据" class="headerlink" title="大数据"></a>大数据</h2><ul>
<li><p>对于“大数据”（Big data）研究机构Gartner给出了这样的定义。“大数据”是需要新处理模式才能具有更强的决策力、洞察发现力和流程优化能力来适应海量、高增长率和多样化的信息资产。</p>
</li>
<li><p>麦肯锡全球研究所给出的定义是：一种规模大到在获取、存储、管理、分析方面大大超出了传统数据库软件工具能力范围的数据集合，具有海量的数据规模、快速的数据流转、多样的数据类型和价值密度低四大特征。 [3] </p>
</li>
<li><p>大数据技术的战略意义不在于掌握庞大的数据信息，而在于对这些含有意义的数据进行专业化处理。换而言之，如果把大数据比作一种产业，那么这种产业实现盈利的关键，在于提高对数据的“加工能力”，通过“加工”实现数据的“增值”。 [4] </p>
</li>
<li><p>从技术上看，大数据与云计算的关系就像一枚硬币的正反面一样密不可分。大数据必然无法用单台的计算机进行处理，必须采用分布式架构。它的特色在于对海量数据进行分布式数据挖掘。但它必须依托云计算的分布式处理、分布式数据库和云存储、虚拟化技术。 [1] </p>
</li>
<li><p>随着云时代的来临，大数据（Big data）也吸引了越来越多的关注。分析师团队认为，大数据（Big data）通常用来形容一个公司创造的大量非结构化数据和半结构化数据，这些数据在下载到关系型数据库用于分析时会花费过多时间和金钱。大数据分析常和云计算联系到一起，因为实时的大型数据集分析需要像<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/MapReduce/133425">MapReduce</a>一样的框架来向数十、数百或甚至数千的电脑分配工作。</p>
</li>
<li><p>大数据需要特殊的技术，以有效地处理大量的容忍经过时间内的数据。适用于大数据的技术，包括大规模并行处理（MPP）数据库、数据挖掘、<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E5%88%86%E5%B8%83%E5%BC%8F%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F/1250388">分布式文件系统</a>、<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E5%88%86%E5%B8%83%E5%BC%8F%E6%95%B0%E6%8D%AE%E5%BA%93/1238109">分布式数据库</a>、云计算平台、互联网和可扩展的存储系统。</p>
</li>
</ul>
<p><img src="http://xiaoziyan.top/images/image-20211011093200168.png"></p>
<h2 id="Hadoop"><a href="#Hadoop" class="headerlink" title="Hadoop"></a>Hadoop</h2><p><code>Hadoop</code> 是一个分布式系统基础架构，由Apache基金会开发。用户可以在不了解分布式底层细节的情况下，开发分布式程序。充分利用集群的威力高速运算和存储。Hadoop实现了一个分布式文件系统（<code>Hadoop Distributed File System</code>），简称<code>HDFS</code>。<a target="_blank" rel="noopener" href="http://www.oschina.net/p/hdfs">HDFS</a>有着高容错性的特点，并且设计用来部署在低廉的（<code>low-cost</code>）硬件上。而且它提供高传输率（<code>high throughput</code>）来访问应用程序的数据，适合那些有着超大数据集（large data set）的应用程序。HDFS放宽了（<code>relax</code>）<code>POSIX</code>的要求（<code>requirements</code>）这样可以流的形式访问（<code>streaming access</code>）文件系统中的数据。</p>
<p>下图是Hadoop的体系结构：</p>
<p><img src="http://xiaoziyan.top/images/183728_qCnc_12.png"></p>
<h2 id="Hadoop的安装步骤"><a href="#Hadoop的安装步骤" class="headerlink" title="Hadoop的安装步骤"></a>Hadoop的安装步骤</h2><p>首先需要安装好VMware 和CentOS系统<br>第一步:配置CentOS的网络ip 最好固定ip 不然每次启动ip都有可能会发生变化</p>
<p><img src="http://xiaoziyan.top/images/image-20211011094839651.png"></p>
<p>配置网卡信息:</p>
<p><img src="http://xiaoziyan.top/images/image-20211011095132168.png"></p>
<ul>
<li><p>第二步:将机器名绑定对应的ip<br>vim /etc/hosts<br>192.168.10.110 hadoop</p>
</li>
<li><p>第三步:关闭Centos 防火墙<br>#查看防火墙状态<br>service iptables status<br>#关闭防火墙<br>service iptables stop<br>#查看防火墙开机启动状态<br>chkconfig iptables –list<br>#关闭防火墙开机启动<br>chkconfig iptables off</p>
</li>
<li><p>第四步:重启linux系统<br>reboot</p>
</li>
<li><p>第五步:使用FileZilla 工具上传jdk安装包然后安装jdk’<br>解压jdk<br>#创建文件夹<br>mkdir /home/hadoop/app<br>#解压<br>tar -zxvf jdk-7u55-linux-i586.tar.gz -C /home/hadoop/app</p>
</li>
<li><p>第六步：配置jdk的环境变量<br>将java添加到环境变量中<br>vim /etc/profile<br>#在文件最后添加<br>export JAVA_HOME=/home/hadoop/app/jdk-7u_65-i585<br>export PATH=$PATH:$JAVA_HOME/bin<br>#刷新配置<br>source /etc/profile</p>
</li>
<li><p>第七步: 使用FileZilla 工具上传hadoop 的工具包并且解压<br>tar -zxvf hadoop.2.4.1.tar.gz -C /home/hadoop/app</p>
</li>
<li><p>第八步:配置 hadoop的环境变量<br>vi /etc/proflie<br>export HADOOP_HOME=/app/hadoop-2.4.1<br>export<br>PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin<br>source /etc/profile</p>
</li>
<li><p>第九步:修改hadoop配置文件</p>
</li>
</ul>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line">#第一个：hadoop‐env.sh</span><br><span class="line">vim hadoop‐env.sh</span><br><span class="line">#第27行</span><br><span class="line">export JAVA_HOME=/usr/java/jdk1.7.0_65</span><br><span class="line"></span><br><span class="line">#第二个：core‐site.xml</span><br><span class="line">&lt;!‐‐ 指定HADOOP所使用的文件系统schema（URI），HDFS的老大（NameNode）的地址 ‐‐&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">name</span>&gt;</span>fs.defaultFS<span class="tag">&lt;/<span class="name">name</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">value</span>&gt;</span>hdfs://hadoop:9000<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">&lt;!‐‐ 指定hadoop运行时产生文件的存储目录 ‐‐&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">name</span>&gt;</span>hadoop.tmp.dir<span class="tag">&lt;/<span class="name">name</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">value</span>&gt;</span>/home/hadoop/hadoop‐2.4.1/tmp<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"></span><br><span class="line">#第三个：hdfs‐site.xml hdfs‐default.xml (3)</span><br><span class="line">&lt;!‐‐ 指定HDFS副本的数量 ‐‐&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">name</span>&gt;</span>dfs.replication<span class="tag">&lt;/<span class="name">name</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">value</span>&gt;</span>1<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"></span><br><span class="line">#第四个：mapred‐site.xml (mv mapred‐site.xml.template mapred‐site.xml)</span><br><span class="line">mv mapred‐site.xml.template mapred‐site.xml</span><br><span class="line">vim mapred‐site.xml</span><br><span class="line">&lt;!‐‐ 指定mr运行在yarn上 ‐‐&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">name</span>&gt;</span>mapreduce.framework.name<span class="tag">&lt;/<span class="name">name</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">value</span>&gt;</span>yarn<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"></span><br><span class="line">#第五个：yarn‐site.xml</span><br><span class="line">&lt;!‐‐ 指定YARN的老大（ResourceManager）的地址 ‐‐&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">name</span>&gt;</span>yarn.resourcemanager.hostname<span class="tag">&lt;/<span class="name">name</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">value</span>&gt;</span>weekend‐1206‐01<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">&lt;!‐‐ reducer获取数据的方式 ‐‐&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">name</span>&gt;</span>yarn.nodemanager.aux‐services<span class="tag">&lt;/<span class="name">name</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">value</span>&gt;</span>mapreduce_shuffle<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br></pre></td></tr></table></figure>

<ul>
<li><p>第十步:初始化hadoop配置：<br>hdfs namenode -format (hadoop namenode -format)</p>
</li>
<li><p>第十一步:启动hadoop<br>先启动HDFS<br>sbin/start-dfs.sh<br>再启动YARN<br>sbin/start-yarn.sh<br>或者启动所有<br>sbin/start-all.sh</p>
</li>
<li><p>第十二步：测试hadoop 浏览器输入 <a target="_blank" rel="noopener" href="http://192.168.10.110:50070/">http://192.168.10.110:50070/</a> 服务器ip:50070</p>
</li>
<li><p>第十三步:搭建ssh 无密访问<br>通过ssh 空间生成一个密钥<br>ssh-keygen -t rsa 不停的回车<br>查看</p>
</li>
</ul>
<p><img src="http://xiaoziyan.top/images/image-20211011095709799.png"></p>
<ul>
<li>第十三步:搭建ssh 无密访问<br>通过ssh 空间生成一个密钥<br>ssh-keygen -t rsa 不停的回车</li>
</ul>
<p><img src="http://xiaoziyan.top/images/image-20211011095746898.png"></p>
<p>查看生成的.ssh目录<br>cd /home /hadoop 目录<br>ls -la 查看所有文件<br><img src="http://xiaoziyan.top/images/image-20211011095825196.png"></p>
<p>进入.ssh目录查看</p>
<p><img src="http://xiaoziyan.top/images/image-20211011095847545.png"></p>
<p>拷贝 生成的id_rsa.pub 加密密钥到 ssh安全认证的文件中<br>cp id_rsa.pub authorized_keys</p>
<p><img src="http://xiaoziyan.top/images/image-20211011095922382.png"></p>
<h2 id="HDFS简介及其基本概念"><a href="#HDFS简介及其基本概念" class="headerlink" title="HDFS简介及其基本概念"></a>HDFS简介及其基本概念</h2><p>​        <code>HDFS</code>（Hadoop Distributed File System）是hadoop生态系统的一个重要组成部分，是hadoop中的的存储组件， 在整个Hadoop 中的地位非同一般， 是最基础的一部分， 因为它涉及到数据存储，MapReduce等计算模型都要依赖于存储在HDFS中的数据。HDFS是一个分布式文件系统，以流式数据访问模式存储超大文件，将数据分块存储到一个商业硬件集群内的不同机器上。</p>
<h4 id="这里重点介绍其中涉及到的几个概念："><a href="#这里重点介绍其中涉及到的几个概念：" class="headerlink" title="这里重点介绍其中涉及到的几个概念："></a>这里重点介绍其中涉及到的几个概念：</h4><blockquote>
<p>（1）超大文件。目前的hadoop集群能够存储几百TB甚至PB级的数据。</p>
<p>（2）流式数据访问。HDFS的访问模式是：一次写入，多次读取，更加关注的是读取整个数据集的整体时间。</p>
<p>（3）商用硬件。HDFS集群的设备不需要多么昂贵和特殊，只要是一些日常使用的普通硬件即可，正因为如此，hdfs节点故障的可能性还是很高的，所以必须要有机制来处理这种单点故障，保证数据的可靠。</p>
<p>（4）不支持低时间延迟的数据访问。hdfs关心的是高数据吞吐量，不适合那些要求低时间延迟数据访问的应用。</p>
<p>（5）单用户写入，不支持任意修改。hdfs的数据以读为主，只支持单个写入者，并且写操作总是以添加的形式在文末追加，不支持在任意位置进行修改。</p>
</blockquote>
<h3 id="HDFS数据块"><a href="#HDFS数据块" class="headerlink" title="HDFS数据块"></a>HDFS数据块</h3><p>​        每个磁盘都有默认的数据块大小，这是文件系统进行数据读写的最小单位。这涉及到磁盘的相应知识，这里我们不多讲，后面整理一篇博客来记录一下磁盘的相应知识。<br>​        <code>HDFS</code>同样也有数据块的概念，默认一个块（block）的大小为128MB（HDFS的块这么大主要是为了最小化寻址开销），要在HDFS中存储的文件可以划分为多个分块，每个分块可以成为一个独立的存储单元。与本地磁盘不同的是，HDFS中小于一个块大小的文件并不会占据整个HDFS数据块。</p>
<p>对HDFS存储进行分块有很多好处：</p>
<ul>
<li>一个文件的大小可以大于网络中任意一个磁盘的容量，文件的块可以利用集群中的任意一个磁盘进行存储。</li>
<li>使用抽象的块，而不是整个文件作为存储单元，可以简化存储管理，使得文件的元数据可以单独管理。</li>
<li>冗余备份。数据块非常适合用于数据备份，进而可以提供数据容错能力和提高可用性。每个块<br>可以有多个备份（默认为三个），分别保存到相互独立的机器上去，这样就可以保证单点故障不会<br>导致数据丢失。</li>
</ul>
<h3 id="namenode和datanode"><a href="#namenode和datanode" class="headerlink" title="namenode和datanode"></a>namenode和datanode</h3><blockquote>
<p>​        HDFS集群的节点分为两类：namenode和datanode，以管理节点工作节点的模式运行，即一个namenode和多个datanode，理解这两类节点对理解HDFS工作机制非常重要。<br>​        namenode作为管理节点，它负责整个文件系统的命名空间，并且维护着文件系统树和整棵树内所有的文件和目录，这些信息以两个文件的形式（命名空间镜像文件和编辑日志文件）永久存储在namenode的本地磁盘上。除此之外，同时，namenode也记录每个文件中各个块所在的数据节点信息，但是不永久<br>存储块的位置信息，因为块的信息可以在系统启动时重新构建。<br>​        datanode作为文件系统的工作节点，根据需要存储并检索数据块，定期向namenode发送他们所存储的块的列表。</p>
</blockquote>
<p><img src="http://xiaoziyan.top/images/image-20211011100349957.png"></p>
<h4 id="为了使得namenode更加可靠，hadoop提供了两种机制："><a href="#为了使得namenode更加可靠，hadoop提供了两种机制：" class="headerlink" title="为了使得namenode更加可靠，hadoop提供了两种机制："></a>为了使得namenode更加可靠，hadoop提供了两种机制：</h4><ul>
<li>第一种机制是备份那些组成文件系统元数据持久状态的文件，比如：将文件系统的信息写入本地磁盘的同时，也写入一个远程挂载的网络文件系统（NFS），这些写操作实时同步并且保证原子性。</li>
<li>第二种机制是运行一个辅助namenode，用以保存命名空间镜像的副本，在namenode发生故障时启用。（也可以使用热备份namenode代替辅助namenode）。</li>
</ul>
<p><img src="http://xiaoziyan.top/images/image-20211011100505709.png"></p>
<h3 id="HDFS常见shell命令"><a href="#HDFS常见shell命令" class="headerlink" title="HDFS常见shell命令"></a>HDFS常见shell命令</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">hdfs dfs ‐mkdir input</span><br><span class="line"><span class="meta">#</span><span class="bash">在HDFS文件系统中创建一个<span class="string">&#x27;input&#x27;</span>目录</span></span><br><span class="line"></span><br><span class="line">hdfs dfs ‐ls input</span><br><span class="line"><span class="meta">#</span><span class="bash">列出 input 目录下的内容</span></span><br><span class="line"></span><br><span class="line">hdfs dfs ‐put /home/hadoop/myFlie.txt input</span><br><span class="line"><span class="meta">#</span><span class="bash">将本地的文件myFile.txt上传到HDFS文件系统的input中。</span></span><br><span class="line"></span><br><span class="line">hdfs dfs ‐get input/myFlie.txt /home/hadoop/下载</span><br><span class="line"><span class="meta">#</span><span class="bash">从HDFS文件系统中下载文件到本地文件系统</span></span><br><span class="line"></span><br><span class="line">hdfs dfs ‐cat input/myFlie.txt</span><br><span class="line"><span class="meta">#</span><span class="bash">查看文件的全部内容</span></span><br><span class="line"></span><br><span class="line">hdfs dfs ‐cp input/myFile.txt input</span><br><span class="line"><span class="meta">#</span><span class="bash">在HDFS上复制文件</span></span><br><span class="line"></span><br><span class="line">hdfs dfs ‐mv input/myFile.txt output</span><br><span class="line"><span class="meta">#</span><span class="bash">在HDFS上移动文件</span></span><br><span class="line"></span><br><span class="line">hdfs dfs ‐rm input/myFile.txt</span><br><span class="line"><span class="meta">#</span><span class="bash">从HDFS删除文件</span></span><br><span class="line"></span><br><span class="line">hdfs dfs ‐du input/myFile.txt</span><br><span class="line"><span class="meta">#</span><span class="bash">查看HDFS上某目录下所有文件大小，指定文件后显示具体文件大小</span></span><br><span class="line"></span><br><span class="line">hdfs dfs ‐touchz input/file.txt</span><br><span class="line"><span class="meta">#</span><span class="bash">创建一个0字节的空文件。</span></span><br><span class="line"></span><br><span class="line">hdfs dfs ‐chmod</span><br><span class="line"><span class="meta">#</span><span class="bash">改名文件权限</span></span><br><span class="line"></span><br><span class="line">hdfs dfs ‐chown</span><br><span class="line"><span class="meta">#</span><span class="bash">改变文件所有者</span></span><br></pre></td></tr></table></figure>

<h3 id="Java接口以及常用api"><a href="#Java接口以及常用api" class="headerlink" title="Java接口以及常用api"></a>Java接口以及常用api</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.cloud.io;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.apache.hadoop.conf.Configuration;</span><br><span class="line"><span class="keyword">import</span> org.apache.hadoop.fs.FileSystem;</span><br><span class="line"><span class="keyword">import</span> org.apache.hadoop.fs.Path;</span><br><span class="line"><span class="keyword">import</span> org.junit.After;</span><br><span class="line"><span class="keyword">import</span> org.junit.Before;</span><br><span class="line"><span class="keyword">import</span> org.junit.Test;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.net.URI;</span><br><span class="line"><span class="keyword">import</span> java.net.URISyntaxException;</span><br><span class="line"></span><br><span class="line"><span class="comment">//java操作HDFS api</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">new_cloud_io</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    FileSystem fs =<span class="keyword">null</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//先连接服务器</span></span><br><span class="line">    <span class="meta">@Before</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">init</span><span class="params">()</span> <span class="keyword">throws</span> URISyntaxException, IOException, InterruptedException </span>&#123;</span><br><span class="line">        <span class="comment">//配置文件</span></span><br><span class="line">        Configuration conf = <span class="keyword">new</span> Configuration();</span><br><span class="line">        <span class="comment">//建立连接</span></span><br><span class="line">        fs = FileSystem.get(<span class="keyword">new</span> URI(<span class="string">&quot;hdfs://39.98.198.224:9000&quot;</span>),conf,<span class="string">&quot;root&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//创建文件</span></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">mkdirfile</span><span class="params">()</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        fs.mkdirs(<span class="keyword">new</span> Path(<span class="string">&quot;/xiaoziyan/&quot;</span>));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//上传本地文件</span></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">getfile</span><span class="params">()</span><span class="keyword">throws</span> IOException</span>&#123;</span><br><span class="line">        fs.copyFromLocalFile(<span class="keyword">new</span> Path(<span class="string">&quot;D:\\IDEA-project\\test_d-file\\1.mp4&quot;</span>),<span class="keyword">new</span> Path(<span class="string">&quot;/xiaoziyan/20210310/1.mp4&quot;</span>));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//从HDFS上下载文件到本地</span></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">download</span><span class="params">()</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        fs.copyToLocalFile(<span class="keyword">new</span> Path(<span class="string">&quot;/xiaoziyan/out/part-r-00000&quot;</span>),<span class="keyword">new</span> Path(<span class="string">&quot;D:\\download\\data.txt&quot;</span>));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//删除文件</span></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">delete</span><span class="params">()</span> <span class="keyword">throws</span> IOException</span>&#123;</span><br><span class="line">        fs.delete(<span class="keyword">new</span> Path(<span class="string">&quot;/lypxt&quot;</span>));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//运行结束后执行关闭连接</span></span><br><span class="line">    <span class="meta">@After</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">close</span><span class="params">()</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        fs.close();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//这样子有个问题。如果先执行的是download，而还没执行getfile，那download就会出错，因为云端并没有相对应的文件。</span></span><br></pre></td></tr></table></figure>

<h1 id="智慧农业系统"><a href="#智慧农业系统" class="headerlink" title="智慧农业系统"></a>智慧农业系统</h1><h3 id="连接数据库"><a href="#连接数据库" class="headerlink" title="连接数据库"></a>连接数据库</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.chinasofti.sql;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.sql.*;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ConnSql</span> </span>&#123;</span><br><span class="line">    <span class="keyword">public</span>  <span class="keyword">static</span> Connection dbcon=<span class="keyword">null</span>; <span class="comment">//处理与特定数据库的连接</span></span><br><span class="line">    <span class="keyword">public</span>  <span class="keyword">static</span> Statement stmt = <span class="keyword">null</span>;<span class="comment">// 执行语句</span></span><br><span class="line">    <span class="keyword">public</span>  <span class="keyword">static</span> ResultSet rst = <span class="keyword">null</span>;<span class="comment">// 结果集</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">connect</span><span class="params">()</span></span>&#123;</span><br><span class="line">        String driverName=<span class="string">&quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;</span>;</span><br><span class="line">        String dbURL=<span class="string">&quot;jdbc:sqlserver://127.0.0.1:1433;DatabaseName=123&quot;</span>;</span><br><span class="line">        String userName=<span class="string">&quot;xiaoziyan&quot;</span>;            <span class="comment">//sqlserver用户名</span></span><br><span class="line">        String userPwd=<span class="string">&quot;xiaoziyan&quot;</span>;    <span class="comment">//sqlserver用户密码</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">try</span>&#123;</span><br><span class="line">            Class.forName(driverName);   <span class="comment">//加载sqlserver的驱动类</span></span><br><span class="line">            System.out.println(<span class="string">&quot;加载SQLServer驱动类成功!&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">catch</span>(ClassNotFoundException a)&#123;</span><br><span class="line">            System.out.println(<span class="string">&quot;加载SQLServer驱动失败!&quot;</span>);</span><br><span class="line">            a.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">try</span>&#123;</span><br><span class="line">            dbcon= DriverManager.getConnection(dbURL,userName,userPwd);</span><br><span class="line">            System.out.println(<span class="string">&quot;数据库连接成功!&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">catch</span>(SQLException e)&#123;</span><br><span class="line">            System.out.println(<span class="string">&quot;数据库连接失败!&quot;</span>);</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">select</span><span class="params">(String name,String password)</span></span>&#123;</span><br><span class="line"></span><br><span class="line">        String sql=<span class="string">&quot;select count(*) as c from [123].[dbo].[user] where username=&#x27;&quot;</span>+name+<span class="string">&quot;&#x27; and password=&#x27;&quot;</span>+password+<span class="string">&quot;&#x27;&quot;</span>;</span><br><span class="line">        <span class="keyword">int</span> i=<span class="number">0</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            stmt=dbcon.createStatement();</span><br><span class="line">            rst=stmt.executeQuery(sql);</span><br><span class="line">            <span class="keyword">while</span> (rst.next())&#123;</span><br><span class="line">                i=Integer.parseInt(rst.getString(<span class="string">&quot;c&quot;</span>));</span><br><span class="line"></span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (SQLException throwables) &#123;</span><br><span class="line">            throwables.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> i;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">insert</span> <span class="params">(String name,String password)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (name != <span class="string">&quot;&quot;</span>&amp;&amp;password!=<span class="string">&quot;&quot;</span>) &#123;</span><br><span class="line">            String sql = <span class="string">&quot;insert into [123].[dbo].[user] (username,password) values (&#x27;&quot;</span> + name + <span class="string">&quot;&#x27;,&#x27;&quot;</span> + password + <span class="string">&quot;&#x27;)&quot;</span>;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                stmt = dbcon.createStatement();</span><br><span class="line">                rst = stmt.executeQuery(sql);</span><br><span class="line">            &#125; <span class="keyword">catch</span> (SQLException throwables) &#123;</span><br><span class="line">                throwables.printStackTrace();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">        &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="登录验证服务"><a href="#登录验证服务" class="headerlink" title="登录验证服务"></a>登录验证服务</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.chinasofti.Servlet;</span><br><span class="line"><span class="keyword">import</span> com.chinasofti.sql.ConnSql;</span><br><span class="line"><span class="keyword">import</span> net.sf.json.JSONObject;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.ServletException;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.annotation.WebServlet;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.Cookie;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServlet;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletResponse;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">@WebServlet(&quot;/login&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">LoginServlet</span> <span class="keyword">extends</span> <span class="title">HttpServlet</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">service</span><span class="params">(HttpServletRequest request, HttpServletResponse response)</span> <span class="keyword">throws</span> ServletException, IOException </span>&#123;</span><br><span class="line">        <span class="comment">//获取用户界面上传名和密码</span></span><br><span class="line">        String name = request.getParameter(<span class="string">&quot;name&quot;</span>);</span><br><span class="line">        String password = request.getParameter(<span class="string">&quot;pass&quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//创建cookie</span></span><br><span class="line">        Cookie cookie=<span class="keyword">new</span> Cookie(<span class="string">&quot;username&quot;</span>,name);</span><br><span class="line"></span><br><span class="line">        response.addCookie(cookie);</span><br><span class="line"></span><br><span class="line">        ConnSql.connect();</span><br><span class="line">        <span class="keyword">int</span> a=ConnSql.select(name,password);</span><br><span class="line">        System.out.println(a);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//返回json数据</span></span><br><span class="line">        response.setContentType(<span class="string">&quot;txt/html;charset=UTF-8&quot;</span>);</span><br><span class="line">        JSONObject obj = <span class="keyword">new</span> JSONObject();</span><br><span class="line">        <span class="keyword">if</span> (a&gt;<span class="number">0</span>) &#123;</span><br><span class="line">            obj.put(<span class="string">&quot;code&quot;</span>, <span class="number">200</span>);</span><br><span class="line">            obj.put(<span class="string">&quot;msg&quot;</span>, <span class="string">&quot;&quot;</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            obj.put(<span class="string">&quot;code&quot;</span>, <span class="number">500</span>);</span><br><span class="line">            obj.put(<span class="string">&quot;msg&quot;</span>, <span class="string">&quot;错误&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        response.getWriter().write(obj.toString());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="用户注册服务"><a href="#用户注册服务" class="headerlink" title="用户注册服务"></a>用户注册服务</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">package</span> com.chinasofti.Servlet;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.chinasofti.sql.ConnSql;</span><br><span class="line"><span class="keyword">import</span> net.sf.json.JSONObject;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.ServletException;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.annotation.WebServlet;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServlet;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletResponse;</span><br><span class="line"><span class="keyword">import</span> java.io.*;</span><br><span class="line"><span class="meta">@WebServlet(&quot;/regist&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RegisterServlet</span> <span class="keyword">extends</span> <span class="title">HttpServlet</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">service</span><span class="params">(HttpServletRequest request, HttpServletResponse response)</span> <span class="keyword">throws</span> ServletException, IOException </span>&#123;</span><br><span class="line">        String name = request.getParameter(<span class="string">&quot;name&quot;</span>);</span><br><span class="line">        String password = request.getParameter(<span class="string">&quot;pass&quot;</span>);</span><br><span class="line">        System.out.println(<span class="string">&quot;注册的名字&quot;</span>+name);</span><br><span class="line">        System.out.println(<span class="string">&quot;注册的密码&quot;</span>+password);</span><br><span class="line">        <span class="comment">//字符串</span></span><br><span class="line">        String str=<span class="string">&quot;username:&quot;</span>+name+<span class="string">&quot;&amp;&quot;</span>+<span class="string">&quot;password:&quot;</span>+password;</span><br><span class="line">        System.out.println(str);</span><br><span class="line">        ConnSql.connect();</span><br><span class="line">        <span class="keyword">int</span> bl=ConnSql.insert(name,password);</span><br><span class="line">        System.out.println(bl);</span><br><span class="line">        <span class="comment">//返回json数据</span></span><br><span class="line">        response.setContentType(<span class="string">&quot;txt/html;charset=UTF-8&quot;</span>);</span><br><span class="line">        JSONObject obj=<span class="keyword">new</span> JSONObject();</span><br><span class="line">        <span class="keyword">if</span> (bl==<span class="number">0</span>)&#123;</span><br><span class="line">            obj.put(<span class="string">&quot;code&quot;</span>, <span class="number">200</span>);</span><br><span class="line">        &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">            obj.put(<span class="string">&quot;code&quot;</span>, <span class="number">500</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        response.getWriter().write(obj.toString());</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="获取数据"><a href="#获取数据" class="headerlink" title="获取数据"></a>获取数据</h2><h3 id="获取所有数据"><a href="#获取所有数据" class="headerlink" title="获取所有数据"></a>获取所有数据</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.chinasofti.fileServer;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.chinasofti.fileServer.AllData;</span><br><span class="line"><span class="keyword">import</span> com.chinasofti.po.Fistday;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.BufferedReader;</span><br><span class="line"><span class="keyword">import</span> java.io.FileReader;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">GetAlldata</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> List&lt;AllData&gt; <span class="title">readData</span><span class="params">()</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        List&lt;AllData&gt; AllDatas=<span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        BufferedReader rb=<span class="keyword">new</span> BufferedReader(<span class="keyword">new</span> FileReader(<span class="string">&quot;D:\\pxthadoop\\file\\AllData.txt&quot;</span>));</span><br><span class="line">        String len=<span class="keyword">null</span>;</span><br><span class="line">        <span class="keyword">while</span>((len=rb.readLine())!=<span class="keyword">null</span>)&#123;</span><br><span class="line">            AllData allData=<span class="keyword">new</span> AllData();</span><br><span class="line">            String[]strs=len.split(<span class="string">&quot; &quot;</span>);</span><br><span class="line">            allData.setDate(strs[<span class="number">0</span>]);</span><br><span class="line">            allData.setTime(strs[<span class="number">1</span>]);</span><br><span class="line">            allData.setTemper(strs[<span class="number">2</span>]);</span><br><span class="line">            allData.setHumidity(strs[<span class="number">3</span>]);</span><br><span class="line">            allData.setIlluminance(strs[<span class="number">4</span>]);</span><br><span class="line">            allData.setSoil(strs[<span class="number">5</span>]);</span><br><span class="line">            AllDatas.add(allData);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> AllDatas;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        List&lt;AllData&gt; AllDatas= GetAlldata.readData();</span><br><span class="line">        <span class="keyword">for</span> (AllData data:AllDatas)&#123;</span><br><span class="line">            System.out.println(data);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="定义数据"><a href="#定义数据" class="headerlink" title="定义数据"></a>定义数据</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.chinasofti.fileServer;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AllData</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String date;</span><br><span class="line">    <span class="keyword">private</span> String time;</span><br><span class="line">    <span class="keyword">private</span> String temper;</span><br><span class="line">    <span class="keyword">private</span> String humidity;<span class="comment">//湿度</span></span><br><span class="line">    <span class="keyword">private</span> String illuminance;<span class="comment">//光照度</span></span><br><span class="line">    <span class="keyword">private</span> String soil;<span class="comment">//土壤</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getDate</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> date;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setDate</span><span class="params">(String date)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.date = date;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getTime</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> time;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setTime</span><span class="params">(String time)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.time = time;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getTemper</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> temper;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setTemper</span><span class="params">(String temper)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.temper = temper;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getHumidity</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> humidity;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setHumidity</span><span class="params">(String humidity)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.humidity = humidity;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getIlluminance</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> illuminance;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setIlluminance</span><span class="params">(String illuminance)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.illuminance = illuminance;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getSoil</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> soil;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setSoil</span><span class="params">(String soil)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.soil = soil;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">toString</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;AllData&#123;&quot;</span> +</span><br><span class="line">                <span class="string">&quot;date=&#x27;&quot;</span> + date + <span class="string">&#x27;\&#x27;&#x27;</span> +</span><br><span class="line">                <span class="string">&quot;, time=&#x27;&quot;</span> + time + <span class="string">&#x27;\&#x27;&#x27;</span> +</span><br><span class="line">                <span class="string">&quot;, temper=&#x27;&quot;</span> + temper + <span class="string">&#x27;\&#x27;&#x27;</span> +</span><br><span class="line">                <span class="string">&quot;, humidity=&#x27;&quot;</span> + humidity + <span class="string">&#x27;\&#x27;&#x27;</span> +</span><br><span class="line">                <span class="string">&quot;, illuminance=&#x27;&quot;</span> + illuminance + <span class="string">&#x27;\&#x27;&#x27;</span> +</span><br><span class="line">                <span class="string">&quot;, soil=&#x27;&quot;</span> + soil + <span class="string">&#x27;\&#x27;&#x27;</span> +</span><br><span class="line">                <span class="string">&#x27;&#125;&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="数据服务"><a href="#数据服务" class="headerlink" title="数据服务"></a>数据服务</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.chinasofti.fileServer;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.chinasofti.fileServer.AllData;</span><br><span class="line"><span class="keyword">import</span> com.chinasofti.fileServer.GetAlldata;</span><br><span class="line"><span class="keyword">import</span> net.sf.json.JSONArray;</span><br><span class="line"><span class="keyword">import</span> net.sf.json.JSONObject;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.ServletException;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.annotation.WebServlet;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServlet;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletResponse;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="meta">@WebServlet(&quot;/alldata&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AllDataServselt</span> <span class="keyword">extends</span> <span class="title">HttpServlet</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">service</span><span class="params">(HttpServletRequest request, HttpServletResponse response)</span> <span class="keyword">throws</span> ServletException, IOException </span>&#123;</span><br><span class="line">        response.setContentType(<span class="string">&quot;txt/html;charset=UTF-8&quot;</span>);</span><br><span class="line">        JSONObject obj=<span class="keyword">new</span> JSONObject();</span><br><span class="line">        List&lt;AllData&gt; AllDatas= GetAlldata.readData();</span><br><span class="line">        obj.put(<span class="string">&quot;data&quot;</span>, JSONArray.fromObject(AllDatas));</span><br><span class="line">        response.getWriter().write(obj.toString());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="首页代码"><a href="#首页代码" class="headerlink" title="首页代码"></a>首页代码</h3><figure class="highlight jsp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br></pre></td><td class="code"><pre><span class="line">&lt;%@ page contentType=<span class="string">&quot;text/html;charset=UTF-8&quot;</span> language=<span class="string">&quot;java&quot;</span> %&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">  &lt;meta charset=<span class="string">&quot;utf-8&quot;</span>&gt;</span><br><span class="line">  &lt;meta name=<span class="string">&quot;viewport&quot;</span> content=<span class="string">&quot;width=device-width, initial-scale=1, maximum-scale=1&quot;</span>&gt;</span><br><span class="line">  &lt;title&gt;index&lt;/title&gt;</span><br><span class="line">  &lt;link rel=<span class="string">&quot;stylesheet&quot;</span> href=<span class="string">&quot;layui/css/layui.css&quot;</span>&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-layout layui-layout-admin&quot;</span>&gt;</span><br><span class="line">  &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-header&quot;</span>&gt;</span><br><span class="line">    &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-logo layui-hide-xs layui-bg-black&quot;</span> onclick=<span class="string">&quot;window.location.href=&#x27;index.jsp&#x27;;&quot;</span>&gt;智慧农业系统&lt;/div&gt;</span><br><span class="line">    &lt;!-- 头部区域（可配合layui 已有的水平导航） --&gt;</span><br><span class="line">    &lt;ul <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav layui-layout-left&quot;</span>&gt;</span><br><span class="line">      &lt;!-- 移动端显示 --&gt;</span><br><span class="line">      &lt;li <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-item layui-show-xs-inline-block layui-hide-sm&quot;</span> lay-header-event=<span class="string">&quot;menuLeft&quot;</span>&gt;</span><br><span class="line">        &lt;i <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-icon layui-icon-spread-left&quot;</span>&gt;&lt;/i&gt;</span><br><span class="line">      &lt;/li&gt;</span><br><span class="line">      &lt;li <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-item&quot;</span>&gt;</span><br><span class="line">        &lt;a href=<span class="string">&quot;javascript:;&quot;</span>&gt;+新增&lt;/a&gt;</span><br><span class="line">        &lt;dl <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-child&quot;</span>&gt;</span><br><span class="line">          &lt;dd&gt;&lt;a onclick=<span class="string">&quot;x_admin_show(&#x27;资讯&#x27;,&#x27;http://www.baidu.com&#x27;)&quot;</span>&gt;&lt;i <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;iconfont&quot;</span>&gt;&amp;#xe6a2;&lt;/i&gt;资讯&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">          &lt;dd&gt;&lt;a onclick=<span class="string">&quot;x_admin_show(&#x27;图片&#x27;,&#x27;http://www.baidu.com&#x27;)&quot;</span>&gt;&lt;i <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;iconfont&quot;</span>&gt;&amp;#xe6a8;&lt;/i&gt;图片&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">          &lt;dd&gt;&lt;a onclick=<span class="string">&quot;x_admin_show(&#x27;用户&#x27;,&#x27;http://www.baidu.com&#x27;)&quot;</span>&gt;&lt;i <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;iconfont&quot;</span>&gt;&amp;#xe6b8;&lt;/i&gt;用户&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">        &lt;/dl&gt;</span><br><span class="line">      &lt;/li&gt;</span><br><span class="line">    &lt;/ul&gt;</span><br><span class="line">    &lt;ul <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav layui-layout-right&quot;</span>&gt;</span><br><span class="line">      &lt;li <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-item layui-hide layui-show-md-inline-block&quot;</span>&gt;</span><br><span class="line">        &lt;a href=<span class="string">&quot;javascript:;&quot;</span>&gt;</span><br><span class="line">          &lt;img  src=<span class="string">&quot;//tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg&quot;</span> <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-img&quot;</span>&gt;</span><br><span class="line">          &lt;span  id=<span class="string">&quot;user-name&quot;</span>&gt;用户名&lt;/span&gt;</span><br><span class="line">        &lt;/a&gt;</span><br><span class="line">        &lt;dl <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-child&quot;</span>&gt;</span><br><span class="line">          &lt;dd&gt;&lt;a onclick=<span class="string">&quot;x_admin_show(&#x27;切换帐号&#x27;,&#x27;http://www.baidu.com&#x27;)&quot;</span>&gt;个人信息&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">          &lt;dd&gt;&lt;a onclick=<span class="string">&quot;x_admin_show(&#x27;切换帐号&#x27;,&#x27;http://www.baidu.com&#x27;)&quot;</span>&gt;切换账户&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">          &lt;dd&gt;&lt;a href=<span class="string">&quot;login.jsp&quot;</span>&gt;退出&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">        &lt;/dl&gt;</span><br><span class="line">      &lt;/li&gt;</span><br><span class="line">    &lt;/ul&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line"></span><br><span class="line">  &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-side layui-bg-black&quot;</span>&gt;</span><br><span class="line">    &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-side-scroll&quot;</span>&gt;</span><br><span class="line">      &lt;!-- 左侧导航区域（可配合layui已有的垂直导航） --&gt;</span><br><span class="line">      &lt;ul <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav layui-nav-tree &quot;</span> lay-filter=<span class="string">&quot;test&quot;</span>&gt;</span><br><span class="line">        &lt;li <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-item layui-nav-itemed&quot;</span> &gt;</span><br><span class="line">          &lt;a <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;&quot;</span> href=<span class="string">&quot;javascript:;&quot;</span>&gt;实时监测模块&lt;/a&gt;</span><br><span class="line">          &lt;dl <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-child &quot;</span> &gt;</span><br><span class="line">            &lt;dd&gt;&lt;a href=<span class="string">&quot;realData/TempDate.jsp&quot;</span>&gt;空气温度&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">            &lt;dd&gt;&lt;a href=<span class="string">&quot;realData/HumiData.jsp&quot;</span>&gt;空气湿度&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">            &lt;dd&gt;&lt;a href=<span class="string">&quot;realData/IllumData.jsp&quot;</span>&gt;光照强度&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">            &lt;dd&gt;&lt;a href=<span class="string">&quot;realData/TourData.jsp&quot;</span>&gt;土壤湿度&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">          &lt;/dl&gt;</span><br><span class="line">        &lt;/li&gt;</span><br><span class="line">        &lt;li <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-item&quot;</span>&gt;</span><br><span class="line">          &lt;a href=<span class="string">&quot;javascript:;&quot;</span>&gt;数据分析模块&lt;/a&gt;</span><br><span class="line">          &lt;dl <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-child &quot;</span> &gt;</span><br><span class="line">            &lt;dd&gt;&lt;a href=<span class="string">&quot;weekTemp/temperaturemaxormin.jsp&quot;</span>&gt;空气温度&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">            &lt;dd&gt;&lt;a href=<span class="string">&quot;weekHumi/weekHumiData.jsp&quot;</span>&gt;空气湿度&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">            &lt;dd&gt;&lt;a href=<span class="string">&quot;weekHumi/weekIllumData.jsp&quot;</span>&gt;光照强度&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">            &lt;dd&gt;&lt;a href=<span class="string">&quot;weekHumi/weekTourData.jsp&quot;</span>&gt;土壤湿度&lt;/a&gt;&lt;/dd&gt;</span><br><span class="line">          &lt;/dl&gt;</span><br><span class="line">        &lt;/li&gt;</span><br><span class="line">        &lt;li <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-item&quot;</span>&gt;</span><br><span class="line">          &lt;a href=<span class="string">&quot;javascript:;&quot;</span>&gt;应用开发&lt;/a&gt;</span><br><span class="line">        &lt;/li&gt;</span><br><span class="line">        &lt;li <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-nav-item&quot;</span>&gt;</span><br><span class="line">          &lt;a href=<span class="string">&quot;javascript:;&quot;</span>&gt;关于我们&lt;/a&gt;</span><br><span class="line">        &lt;/li&gt;</span><br><span class="line">      &lt;/ul&gt;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line"></span><br><span class="line">  &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-body&quot;</span>&gt;</span><br><span class="line">    &lt;!-- 内容主体区域 --&gt;</span><br><span class="line">    &lt;!--主体承载页面跳转框--&gt;</span><br><span class="line">    &lt;iframe id=<span class="string">&quot;iframeMain&quot;</span> src=<span class="string">&quot;&quot;</span> style=<span class="string">&quot;width: 100%&quot;</span>; height=<span class="string">&quot;100%&quot;</span>; &gt;&lt;/iframe&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line"></span><br><span class="line">  &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;layui-footer&quot;</span>&gt;</span><br><span class="line">    &lt;!-- 底部固定区域 --&gt;</span><br><span class="line">    底部固定区域</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">&lt;/div&gt;</span><br><span class="line">&lt;script src=<span class="string">&quot;layui/layui.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line">&lt;script src=<span class="string">&quot;js/jquery.js&quot;</span>&gt;&lt;/script&gt;</span><br><span class="line">&lt;script&gt;</span><br><span class="line">  $(function () &#123;</span><br><span class="line">    $.ajax(&#123;</span><br><span class="line">      url:<span class="string">&quot;/pxthadoop/index&quot;</span>,</span><br><span class="line">      type:<span class="string">&quot;post&quot;</span>,</span><br><span class="line">      dataType:<span class="string">&quot;text&quot;</span>,</span><br><span class="line">      Async:<span class="keyword">false</span>,</span><br><span class="line">      success:function (data) &#123;</span><br><span class="line">         <span class="comment">/*alert(data);*/</span></span><br><span class="line">        <span class="keyword">var</span> content=document.getElementById(<span class="string">&quot;user-name&quot;</span>);</span><br><span class="line">        content.innerText=data;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;)</span><br><span class="line">  <span class="comment">//JS</span></span><br><span class="line">  layui.use([<span class="string">&#x27;element&#x27;</span>, <span class="string">&#x27;layer&#x27;</span>, <span class="string">&#x27;util&#x27;</span>], function()&#123;</span><br><span class="line">    <span class="keyword">var</span> element = layui.element</span><br><span class="line">            ,layer = layui.layer</span><br><span class="line">            ,util = layui.util</span><br><span class="line">            ,$ = layui.$;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//监听导航点击</span></span><br><span class="line">    element.on(<span class="string">&#x27;nav(demo)&#x27;</span>, function(elem)&#123;</span><br><span class="line">      console.log(elem)</span><br><span class="line">      layer.msg(elem.text());</span><br><span class="line">    &#125;);</span><br><span class="line">    <span class="comment">//头部事件</span></span><br><span class="line">    util.event(<span class="string">&#x27;lay-header-event&#x27;</span>, &#123;</span><br><span class="line">      <span class="comment">//左侧菜单事件</span></span><br><span class="line">      menuLeft: function(othis)&#123;</span><br><span class="line">        layer.msg(<span class="string">&#x27;展开左侧菜单的操作&#x27;</span>, &#123;icon: <span class="number">0</span>&#125;);</span><br><span class="line">      &#125;</span><br><span class="line">      ,menuRight: function()&#123;</span><br><span class="line">        layer.open(&#123;</span><br><span class="line">          type: <span class="number">1</span></span><br><span class="line">          ,content: <span class="string">&#x27;&lt;div style=&quot;padding: 15px;&quot;&gt;处理右侧面板的操作&lt;/div&gt;&#x27;</span></span><br><span class="line">          ,area: [<span class="string">&#x27;260px&#x27;</span>, <span class="string">&#x27;100%&#x27;</span>]</span><br><span class="line">          ,offset: <span class="string">&#x27;rt&#x27;</span> <span class="comment">//右上角</span></span><br><span class="line">          ,anim: <span class="number">5</span></span><br><span class="line">          ,shadeClose: <span class="keyword">true</span></span><br><span class="line">        &#125;);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//点击在主页面跳转</span></span><br><span class="line">    $(document).ready(function()&#123;</span><br><span class="line">      $(<span class="string">&quot;dd&gt;a&quot;</span>).click(function (e) &#123;</span><br><span class="line">        e.preventDefault();</span><br><span class="line">        $(<span class="string">&quot;#iframeMain&quot;</span>).attr(<span class="string">&quot;src&quot;</span>,$(<span class="keyword">this</span>).attr(<span class="string">&quot;href&quot;</span>));</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">  &#125;);</span><br><span class="line">&lt;/script&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>

<p><strong>实时温度图：</strong></p>
<p><img src="http://xiaoziyan.top/images/%E5%AE%9E%E6%97%B6%E6%B8%A9%E5%BA%A6%E6%A8%A1%E5%9D%97.png" alt="实时温度模块"></p>
<p><strong>实时空气湿度：</strong></p>
<p><img src="http://xiaoziyan.top/images/%E5%AE%9E%E6%97%B6%E7%A9%BA%E6%B0%94%E6%B9%BF%E5%BA%A6.png" alt="实时空气湿度"></p>
<p><strong>实时光照强度：</strong></p>
<p><img src="http://xiaoziyan.top/images/%E5%AE%9E%E6%97%B6%E5%85%89%E7%85%A7%E5%BC%BA%E5%BA%A6.png" alt="实时光照强度"></p>
<p><strong>实时土壤湿度：</strong></p>
<p><img src="http://xiaoziyan.top/images/%E5%AE%9E%E6%97%B6%E5%9C%9F%E5%A3%A4%E6%B9%BF%E5%BA%A6.png" alt="实时土壤湿度"></p>
<p><strong>温度数据分析</strong></p>
<p><img src="http://xiaoziyan.top/images/image-20211011102158976.png"></p>
<p><strong>空气湿度数据分析</strong> </p>
<p><img src="http://xiaoziyan.top/images/image-20211011102241621.png"></p>
<p><strong>光照强度数据分析</strong></p>
<p><img src="http://xiaoziyan.top/images/image-20211011102317781.png"></p>
<p><strong>土壤湿度数据分析</strong></p>
<p><img src="http://xiaoziyan.top/images/image-20211011102351465.png"></p>
<p><strong>数据库</strong></p>
<p><img src="http://xiaoziyan.top/images/%E6%95%B0%E6%8D%AE%E5%BA%93%E6%88%AA%E5%9B%BE.png" alt="数据库截图"></p>
<a class="btn-beautify button--animated block left larger" href="https://xiaoziyanxiaoludan.gitee.io/xiaoziyan/2021/08/05/%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A%E5%89%8D%E7%AB%AF%E8%AE%BE%E8%AE%A1/" 
  title="智慧农业前端设计"><i class="far fa-hand-point-left"></i><span>智慧农业前端设计</span></a>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">XiaoZiYan</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a target="_blank" rel="noopener" href="https://baidu.com">https://baidu.com</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://xiaoziyanxiaoludan.gitee.io/xiaoziyan" target="_blank">XiaoZiYan</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/xiaoziyan/tags/%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A/">智慧农业</a><a class="post-meta__tags" href="/xiaoziyan/tags/PCB/">PCB</a><a class="post-meta__tags" href="/xiaoziyan/tags/%E5%A4%A7%E6%95%B0%E6%8D%AE/">大数据</a></div><div class="post_share"><div class="social-share" data-image="http://xiaoziyan.top/images/3205a9c3fa4e72ebd71a6101d2812929.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/xiaoziyan/2021/08/05/%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A%E5%89%8D%E7%AB%AF%E8%AE%BE%E8%AE%A1/"><img class="next-cover" src="http://xiaoziyan.top/images/e610f1279851b9e6e3f4c338cfede87f.jpeg" onerror="onerror=null;src='/xiaoziyan/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">智慧农业——前端控制设计</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/xiaoziyan/2021/08/05/%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A%E5%89%8D%E7%AB%AF%E8%AE%BE%E8%AE%A1/" title="智慧农业——前端控制设计"><img class="cover" src="http://xiaoziyan.top/images/e610f1279851b9e6e3f4c338cfede87f.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-05</div><div class="title">智慧农业——前端控制设计</div></div></a></div><div><a href="/xiaoziyan/2021/08/02/%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A%E7%A1%AC%E4%BB%B6%E8%AE%BE%E8%AE%A1/" title="智慧农业——硬件设计"><img class="cover" src="http://xiaoziyan.top/images/69f7d86180b45b7eabeb284a540905af.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-02</div><div class="title">智慧农业——硬件设计</div></div></a></div><div><a href="/xiaoziyan/2021/08/03/%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A%E9%A9%B1%E5%8A%A8%E7%A8%8B%E5%BA%8F%E5%BC%80%E5%8F%91/" title="智慧农业——驱动程序设计"><img class="cover" src="http://xiaoziyan.top/images/a7944f919383883f23a8b3f45788ae9c.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-03</div><div class="title">智慧农业——驱动程序设计</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%A4%A7%E6%95%B0%E6%8D%AE%E7%9B%B8%E5%85%B3%E7%9F%A5%E8%AF%86"><span class="toc-number">1.</span> <span class="toc-text">大数据相关知识</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%A7%E6%95%B0%E6%8D%AE"><span class="toc-number">1.1.</span> <span class="toc-text">大数据</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Hadoop"><span class="toc-number">1.2.</span> <span class="toc-text">Hadoop</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Hadoop%E7%9A%84%E5%AE%89%E8%A3%85%E6%AD%A5%E9%AA%A4"><span class="toc-number">1.3.</span> <span class="toc-text">Hadoop的安装步骤</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#HDFS%E7%AE%80%E4%BB%8B%E5%8F%8A%E5%85%B6%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5"><span class="toc-number">1.4.</span> <span class="toc-text">HDFS简介及其基本概念</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%BF%99%E9%87%8C%E9%87%8D%E7%82%B9%E4%BB%8B%E7%BB%8D%E5%85%B6%E4%B8%AD%E6%B6%89%E5%8F%8A%E5%88%B0%E7%9A%84%E5%87%A0%E4%B8%AA%E6%A6%82%E5%BF%B5%EF%BC%9A"><span class="toc-number">1.4.0.1.</span> <span class="toc-text">这里重点介绍其中涉及到的几个概念：</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#HDFS%E6%95%B0%E6%8D%AE%E5%9D%97"><span class="toc-number">1.4.1.</span> <span class="toc-text">HDFS数据块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#namenode%E5%92%8Cdatanode"><span class="toc-number">1.4.2.</span> <span class="toc-text">namenode和datanode</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%BA%E4%BA%86%E4%BD%BF%E5%BE%97namenode%E6%9B%B4%E5%8A%A0%E5%8F%AF%E9%9D%A0%EF%BC%8Chadoop%E6%8F%90%E4%BE%9B%E4%BA%86%E4%B8%A4%E7%A7%8D%E6%9C%BA%E5%88%B6%EF%BC%9A"><span class="toc-number">1.4.2.1.</span> <span class="toc-text">为了使得namenode更加可靠，hadoop提供了两种机制：</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#HDFS%E5%B8%B8%E8%A7%81shell%E5%91%BD%E4%BB%A4"><span class="toc-number">1.4.3.</span> <span class="toc-text">HDFS常见shell命令</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Java%E6%8E%A5%E5%8F%A3%E4%BB%A5%E5%8F%8A%E5%B8%B8%E7%94%A8api"><span class="toc-number">1.4.4.</span> <span class="toc-text">Java接口以及常用api</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%99%BA%E6%85%A7%E5%86%9C%E4%B8%9A%E7%B3%BB%E7%BB%9F"><span class="toc-number">2.</span> <span class="toc-text">智慧农业系统</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9E%E6%8E%A5%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">2.0.1.</span> <span class="toc-text">连接数据库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%99%BB%E5%BD%95%E9%AA%8C%E8%AF%81%E6%9C%8D%E5%8A%A1"><span class="toc-number">2.0.2.</span> <span class="toc-text">登录验证服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%A8%E6%88%B7%E6%B3%A8%E5%86%8C%E6%9C%8D%E5%8A%A1"><span class="toc-number">2.0.3.</span> <span class="toc-text">用户注册服务</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E6%95%B0%E6%8D%AE"><span class="toc-number">2.1.</span> <span class="toc-text">获取数据</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E6%89%80%E6%9C%89%E6%95%B0%E6%8D%AE"><span class="toc-number">2.1.1.</span> <span class="toc-text">获取所有数据</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9A%E4%B9%89%E6%95%B0%E6%8D%AE"><span class="toc-number">2.1.2.</span> <span class="toc-text">定义数据</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E6%9C%8D%E5%8A%A1"><span class="toc-number">2.1.3.</span> <span class="toc-text">数据服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A6%96%E9%A1%B5%E4%BB%A3%E7%A0%81"><span class="toc-number">2.1.4.</span> <span class="toc-text">首页代码</span></a></li></ol></li></ol></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By XiaoZiYan</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><p><a style="margin-inline:5px"target="_blank" href="https://hexo.io/"> <img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo" title="博客框架为 Hexo" alt="HEXO"></a><a style="margin-inline:5px"target="_blank"href="https://butterfly.js.org/"> <img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender" title="主题采用 Butterfly" alt="Butterfly"></a><a style="margin-inline:5px"target="_blank" href="https://www.jsdelivr.com/"> <img src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&logo=jsDelivr" title="本站使用 Jsdelivr 为静态资源提供CDN加速" alt="Jsdelivr"></a><a style="margin-inline:5px"target="_blank" href="https://github.com/"> <img src="https://img.shields.io/badge/Source-gitee-d021d6?style=flat&logo=Gitee" title="本站项目由 Gitee 托管" alt="Gitee"></a><a style="margin-inline:5px"target="_blank"href="http://creativecommons.org/licenses/by-nc-sa/4.0/"> <img src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&logo=Claris" alt="img" title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"></a></p></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/xiaoziyan/js/utils.js"></script><script src="/xiaoziyan/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><script src="./js/sakura.js"></script><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>function electric_clock_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img id="card-clock-loading" src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-clock/clock/images/weather/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading" class="entered loading"></div></div></div></div></div>';
                console.log('已挂载electric_clock')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='all'|| 'all' ==='all')){

            electric_clock_injector_config()
        } </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax  src="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.js"></script><!-- hexo injector body_end end --></body></html>